package com.qen.encrypt.inter;

import com.alibaba.fastjson2.JSONObject;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * 配合响应加密的接口
 * @author licz
 * @data 2025年07月01日 14:28
 */
public interface ApiResponse {

    /**
     * 响应实体Code
     *
     * @return
     */
    int getCode();

    /**
     * 响应的Message
     *
     * @return
     */
    String getMessage();

    /**
     * 响应的Message
     *
     * @param message
     */
    void setMessage(String message);

    /**
     * 响应的Data
     *
     * @return
     */
    Object getData();

    /**
     * 响应的Data
     *
     * @param data
     */
    void setData(Object data);

    /**
     * 响应是否加密
     *
     * @param encrypt
     */
    void setEncrypt(int encrypt);

    public static void responseJson(int status, Object data, HttpServletResponse response) throws IOException {
        response.setStatus(status);
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        response.getWriter().print(JSONObject.toJSONString(data));
    }

}
